package com.geek.mysql7work.work2;

import com.geek.mysql7work.work2.datasource.ManagementCenter;
import com.geek.mysql7work.work2.service.OrderService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * @Author: lishuangqiang
 * @Date: 2021/12/19
 * @Description:
 */

@Component
public class Test implements InitializingBean {


    @Autowired
    private OrderService orderService;
    @Autowired
    private ManagementCenter managementCenter;

    //    @PostConstruct
    public void insert() throws SQLException {
        String sql = "INSERT INTO geek_order (order_status,pay_status,pay_amount,buyer_name,buyer_phone,buyer_address,create_at,update_at) VALUES('0','0','1','buyer','1234567890','address','2021-12-19 14:43:26','2021-12-19 14:43:26')";
        orderService.insertOne(managementCenter.getDefaultDataSource(), sql);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        String sql = "select  *   from geek_order  order by  id desc limit 1";
        List<Map<String, Object>> res = orderService.query(managementCenter.getSlaveDataSource(), sql);
        System.out.println("work2查询结果为" + res);
    }
}
